
<div id="projects" data-projects="<%= render(template: "projects/index.json.rabl") %>" >



<div class="accordion project-view-title" id="accordion1">

<h1><%= @project.name %></h1>
<p><h4>"<%=@project.description%>"</h4>  </p>

  </div>


<div class="accordion project-view-title" id="accordion2">


<% if @project_announcements.empty? %>
         <p>You currently have no announcements.</p>

<%else%>
      <h3>Announcements</h3>

<div class="accordion-group ">

  <div class="accordion-heading project-listing-header">
    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#managedCollapse0">
     Show/Hide <%= @project_announcements.count %>  Announcements
    </a>
  </div>

  <div id="managedCollapse0" class="accordion-body collapse dash-bg" style="height: 0px; ">

<% @project_announcements.each do |pa| %>
<div class="alert alert-block alert-error fade in">
            <a class="close" data-dismiss="alert" href="#">×</a>
        <h4 class="alert-heading">Topic: <%= pa.topic%></h4>
      <div class="alert alert-block fade in announcement_border">
        <p><%= pa.content %></p>
      </div>
              <%if current_user == pa.user or current_user == @project.owner %>
      <table>
        <tbody>
        <tr>
          <td>
            <h7>Created: <%= pa.created_at%>&nbsp;&nbsp;&nbsp;&nbsp;</h7>

          </td>
          <td>
            <%= link_to "Edit", edit_announcement_path(pa), :class => "btn btn-mini btn-create" %>
          </td>
          <td>
            <%= link_to 'Delete', announcement_path(pa),
                                 :method => :delete,
                                 :confirm => 'Are you sure?',
                                 :class => 'btn btn-mini btn-danger' %>
          </td>
        </tr>
        </tbody>
      </table>


            <%end%>
  <hr>
</div>
<%end%>

  </div>
</div>
<%end%>
<p>
   <%= link_to "Create Announcement", new_project_announcement_path(@project), :class => "btn btn-create" %>
</p>
</div>


<div class="accordion project-view-title" id="accordion3" >
  <h3>Details</h3>

<p>
  <b>Period: </b>
 <%= @project.started_at.strftime("%m/%d/%Y") %> -
  <%= @project.ending_at.strftime("%m/%d/%Y") %>
</p>
<p>
  <h4>Manager:  <%=@project.owner.name  %>     </h4>

</p>

<% if @managed_users.empty? %>
       <b> Contributors</b>
	<div class="alert alert-block fade in">

            <h4 class="alert-heading">No contributors found!</h4>
            <p>Why not invite some members from your online social network?</p>
            <p>
              <%= link_to "Find One", new_project_invitation_path(@project), :class => "btn btn-primary" %>
            </p>
          </div>


<% else %>

<div class="accordion-group">


              <div class="accordion-heading project-listing-header">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion3" href="#managedCollapse1">
                         Show/Hide <%= @managed_users.count%> Contributors
                </a>
              </div>
              <div id="managedCollapse1" class="accordion-body collapse" style="height: 0px; ">
                <div class="accordion-inner">
                        <table class='table table-striped table-bordered'>
      <thead>
        <tr>
        <th>Name</th>
        <th>Email</th>
          <%if current_user == @project.owner %>

        <th>Action</th>
              <%end%>
        </tr>
      </thead>
    <tbody>
       <% @managed_users.each do |pc| %>
    <tr>

            <% if pc != @project.owner %>
              <td><%= pc.name %></td>
              <td><%= pc.email %></td>

            <%if current_user == @project.owner %>
                  <td><%= link_to "Remove", project_contribution_path(@project, pc), :class => "btn btn-mini btn-danger", :confirm => 'Are you sure?', :method => :delete %></td>
            <%end%>


            <%end%>

    </tr>
         <% end %>
    </tbody>
    </table>
    </div>
              </div>


            </div>
       <p>
         <%if current_user == @project.owner %>

<%= link_to "Add contributors", new_project_invitation_path(@project), :class => "btn btn-create" %>


          <%end%>
        </p>
  <% end %>




</div>


<div class="accordion project-view-title" id="accordion4">


<p></p>
<h3>Resources</h3>

<% if @managed_resources.empty? %>

	<div class="alert alert-block fade in">
            
            <h4 class="alert-heading">No Resource Found</h4>
            <p>Add a resource</p>
            <p>
              <%= link_to "Create One", new_project_resource_path(@project), :class => "btn btn-create" %>
            </p>
          </div>


<% else %>

<div class="accordion-group">


              <div class="accordion-heading project-listing-header">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion4" href="#managedCollapse3">
                         Show/Hide <%= @managed_resources.count%> Resources
                </a>
              </div>
              <div id="managedCollapse3" class="accordion-body collapse" style="height: 0px; ">
                <div class="accordion-inner">
                        <table class='table table-striped table-bordered'>

      <thead>
        <tr>
        <th>Name</th>
        <th>Owner</th>
        <th>Description</th>
        <th>Created</th>
        <th>Version</th>
        <th>Actions</th>
        </tr>
      </thead>
    <tbody>
<% @managed_resources.each do |pr| %>
    
    <tr>
        <td><%= link_to pr.name, pr %></td>
        <td><%= pr.user.name %></td>
        <td><%= truncate(pr.description, :length => 30) %></td>
        <td><%= pr.created_at.to_s(:slash_time) %></td>
        <td><%= pr.version %></td>
        <td>
          <% if pr.file.url %>
          <%= link_to "Get", pr.file.url, :class => "btn btn-mini btn-success" %>
          <% else %>
               error: file not found
              <%end%>

          <%if pr.user_id == current_user.id || current_user == @project.owner%>
          <%= link_to "Edit", edit_resource_path(pr), :class => "btn btn-mini btn-create" %>
          <%= link_to 'Delete', resource_path(pr), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>

          <%end%>
        </td>
    </tr>
    
  <% end %>
  </tbody>
    </table>
                  </div>
                </div>
  </div>



  <p><%= link_to "Add Resources", new_project_resource_path(@project), :class => "btn btn-create" %></p>
<% end %>

    </div>


<div class="form-actions project-view-title">
  <%= link_to 'Back', user_path(@project.owner_id), :class => 'btn btn-primary'  %>
  <%if current_user == @project.owner %>
  <%= link_to 'Edit', edit_project_path(@project), :class => 'btn btn-create' %>
  <%= link_to 'Delete', project_path(@project), :method => 'delete', :confirm => 'Are you sure?', :class => 'btn btn-danger' %>
      <% end %>
</div>
</div>

